package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.ProductRule;
import com.eling.elcms.travel.service.IProductRuleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProductRuleController extends BaseFormController{
     
	@Autowired
	private IProductRuleManager productRuleManager;
	
	@RequestMapping("/api/productrule/query")
    @ResponseBody
    public List<ProductRule> query(@ModelAttribute ProductRule cond){
    	return productRuleManager.query(cond); 
    }
	
	@RequestMapping("/api/productrule/search")
    @ResponseBody
    public List<ProductRule> search(@ModelAttribute SearchCondition sc,@ModelAttribute ProductRule cond){
		sc.setQueryCondition(cond);
    	return productRuleManager.search(sc); 
    }
	
	@RequestMapping("/api/productrule/save")
    @ResponseBody
    public ProductRule save(@ModelAttribute ProductRule productRule) {
		return productRuleManager.save(productRule);
    }
	
	@RequestMapping("/api/productrule/{pkProductRule}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkProductRule) {
		productRuleManager.remove(pkProductRule);
	    return new Msg("删除成功");
	}
	
	@RequestMapping("/api/productrule/{pkProductRule}/deleteall")
	@ResponseBody
	public Msg deleteAll(@PathVariable Long pkProductRule) {
	    return productRuleManager.deleteAll(pkProductRule);
	}
	
	/* 
	 * 促销状态修改
	 * 
	 * **/
	@RequestMapping("/api/productrule/updata")
    @ResponseBody
    public ProductRule updata(@ModelAttribute@ModelFilling ProductRule productRule) {
		return productRuleManager.updata(productRule);
    }
}
